import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
} from '@nestjs/common';
import { ShipinleibieService } from './shipinleibie.service';
import { CreateShipinleibieDto } from './dto/create-shipinleibie.dto';
import { UpdateShipinleibieDto } from './dto/update-shipinleibie.dto';
import { SearchPagesDto } from './dto/search-pages.dto';
import { Shipinleibie } from './entities/shipinleibie.entity';

@Controller('/admin/shipinleibie')
export class ShipinleibieController {
  constructor(private readonly shipinleibieService: ShipinleibieService) {}

  // 创建新类别
  @Post()
  create(@Body() createDto: CreateShipinleibieDto) {
    return this.shipinleibieService.create(createDto);
  }

  // 分页查询（带搜索条件）
  @Post('/page')
  findAllPage(@Body() pages: SearchPagesDto) {
    return this.shipinleibieService.findAllPage(pages);
  }

  // 批量删除
  @Post('/deleteList')
  deleteList(@Body() data: { list: Shipinleibie[] }) {
    return this.shipinleibieService.batchRemove(
      data.list.map((item) => item.id),
    );
  }

  // 获取全部数据（可选，根据前端需求）
  @Get()
  findAll() {
    return this.shipinleibieService.findAll();
  }

  // 获取单条详情
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.shipinleibieService.findOne(+id);
  }

  // 更新数据
  @Patch(':id')
  update(@Param('id') id: string, @Body() updateDto: UpdateShipinleibieDto) {
    return this.shipinleibieService.update(+id, updateDto);
  }

  // 删除单条
  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.shipinleibieService.remove(+id);
  }
}
